<?php

namespace app\task\cron\coupon;

use app\model\CouponOrder;
use Carbon\Carbon;
use think\Exception;
use yunwuxin\cron\Task;

class CancleOrder extends Task
{

    /**
     *
     */
    protected function configure()
    {
        // 分 时 日 月 周
        $this->expression = '*/1 * * * *';

    }

    /**
     * 执行指令.
     */
    protected function handle()
    {

        CouponOrder::query()
//            ->where('serv_type',PRODUCT_COUPON_SERV)
            ->where('type',CouponOrder::TYPE_COUPON_SELF_EMPLOYED)
            ->where('pay_status',CouponOrder::C_PAY_STATUS_NO)
            ->where('status',CouponOrder::C_STATUS_NO_SUBMIT)
            ->where('created_at', '>=', '2023-04-28 00:00:00')
            ->where('created_at','<',Carbon::now()->subMinutes(10))
            ->select()->each(function (CouponOrder $couponOrder){
                $couponOrder->where('pay_status',CouponOrder::C_PAY_STATUS_NO)
                    ->update([
                        'status' => CouponOrder::C_STATUS_TIMEOUT_CLOSE
                    ]);
            });
    }
}